﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using StockholmsStad.Business;
using StockholmsStad.Runtime.Serialization.DataContract.Enums;
using StockholmsStad.Utilities.Exceptions;
using StockholmsStad.Runtime.Serialization.DataContract;
using StockholmsStad.ServiceModel.Interfaces;

namespace StockholmsStad.ServiceModel.Services
{
    /// <summary>
    /// Detta är serviceimplementationsklassen för servicen ICeremonyService.
    /// </summary>
    public class CeremonyService : ICeremonyService
    {
        #region ICeremonyService Members


        //TODO Flytta alla metoder som har men Ceremony till denna tjänst

        /// <summary>
        /// 
        /// </summary>
        /// <param name="user"></param>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public List<CeremonySummary> GetIndividualCeremonyBookingForDate(User user, DateTime dateTime)
        {
            try
            {
                var ceremonyBusiness = new CeremonyBusiness(user);
                return ceremonyBusiness.GetIndividualCeremonyBooking(dateTime);
            }
            catch (StockholmStadSystemException e)
            {
                throw new FaultException<StockholmStadSystemErrorFault>(new StockholmStadSystemErrorFault(e.ErrorCode, e.Message));
            }
            catch (StockholmStadApplicationException e)
            {
                throw new FaultException<StockholmStadApplicationErrorFault>(new StockholmStadApplicationErrorFault(e.ErrorCode, e.Message));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="user"></param>
        /// <param name="fromDate"></param>
        /// <param name="toDate"></param>
        /// <param name="ministerId"></param>
        /// <returns></returns>
        public List<CeremonySummary> GetIndividualCeremonyBooking(User user, DateTime fromDate, DateTime? toDate, int? ministerId)
        {
            try
            {
                var ceremonyBusiness = new CeremonyBusiness(user);
                return ceremonyBusiness.GetIndividualCeremonyBooking(fromDate, toDate, ministerId);
            }
            catch (StockholmStadSystemException e)
            {
                throw new FaultException<StockholmStadSystemErrorFault>(new StockholmStadSystemErrorFault(e.ErrorCode, e.Message));
            }
            catch (StockholmStadApplicationException e)
            {
                throw new FaultException<StockholmStadApplicationErrorFault>(new StockholmStadApplicationErrorFault(e.ErrorCode, e.Message));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="user"></param>
        /// <param name="dateTime"></param>
        /// <param name="ministerId"></param>
        /// <returns></returns>
        public List<CeremonySummaryDetails> GetIndividualCeremonyBookingDetails(User user, DateTime dateTime, int? ministerId)
        {
            try
            {
                var ceremonyBusiness = new CeremonyBusiness(user);
                return ceremonyBusiness.GetIndividualCeremonyBookingDetails(dateTime, ministerId);
            }
            catch (StockholmStadSystemException e)
            {
                throw new FaultException<StockholmStadSystemErrorFault>(new StockholmStadSystemErrorFault(e.ErrorCode, e.Message));
            }
            catch (StockholmStadApplicationException e)
            {
                throw new FaultException<StockholmStadApplicationErrorFault>(new StockholmStadApplicationErrorFault(e.ErrorCode, e.Message));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="user"></param>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public List<CeremonySummary> GetOrdinaryCeremonyBookingForDate(User user, DateTime dateTime)
        {
            try
            {
                var ceremonyBusiness = new CeremonyBusiness(user);
                return ceremonyBusiness.GetOrdinaryCeremonyBooking(dateTime);
            }
            catch (StockholmStadSystemException e)
            {
                throw new FaultException<StockholmStadSystemErrorFault>(new StockholmStadSystemErrorFault(e.ErrorCode, e.Message));
            }
            catch (StockholmStadApplicationException e)
            {
                throw new FaultException<StockholmStadApplicationErrorFault>(new StockholmStadApplicationErrorFault(e.ErrorCode, e.Message));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="user"></param>
        /// <param name="fromDate"></param>
        /// <param name="toDate"></param>
        /// <param name="ministerId"></param>
        /// <returns></returns>
        public List<CeremonySummary> GetOrdinaryCeremonyBooking(User user, DateTime fromDate, DateTime? toDate, int? ministerId)
        {
            try
            {
                var ceremonyBusiness = new CeremonyBusiness(user);
                return ceremonyBusiness.GetOrdinaryCeremonyBooking(fromDate, toDate, ministerId);
            }
            catch (StockholmStadSystemException e)
            {
                throw new FaultException<StockholmStadSystemErrorFault>(new StockholmStadSystemErrorFault(e.ErrorCode, e.Message));
            }
            catch (StockholmStadApplicationException e)
            {
                throw new FaultException<StockholmStadApplicationErrorFault>(new StockholmStadApplicationErrorFault(e.ErrorCode, e.Message));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="user"></param>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public List<CeremonySummaryDetails> GetOrdinaryCeremonyBookingDetails(User user, DateTime dateTime)
        {
            try
            {
                var ceremonyBusiness = new CeremonyBusiness(user);
                return ceremonyBusiness.GetOrdinaryCeremonyBookingDetails(dateTime);
            }
            catch (StockholmStadSystemException e)
            {
                throw new FaultException<StockholmStadSystemErrorFault>(new StockholmStadSystemErrorFault(e.ErrorCode, e.Message));
            }
            catch (StockholmStadApplicationException e)
            {
                throw new FaultException<StockholmStadApplicationErrorFault>(new StockholmStadApplicationErrorFault(e.ErrorCode, e.Message));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public DateTime GetNextCeremonyDateForIndividualService(User user)
        {
            try
            {
                var ceremonyBusiness = new CeremonyBusiness(user);
                return ceremonyBusiness.GetNextCeremonyDateForIndividualService();
            }
            catch (StockholmStadSystemException e)
            {
                throw new FaultException<StockholmStadSystemErrorFault>(new StockholmStadSystemErrorFault(e.ErrorCode, e.Message));
            }
            catch (StockholmStadApplicationException e)
            {
                throw new FaultException<StockholmStadApplicationErrorFault>(new StockholmStadApplicationErrorFault(e.ErrorCode, e.Message));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public DateTime GetNextCeremonyDateForOrdinaryService(User user)
        {
            try
            {
                var ceremonyBusiness = new CeremonyBusiness(user);
                return ceremonyBusiness.GetNextCeremonyDateForOrdinaryService();
            }
            catch (StockholmStadSystemException e)
            {
                throw new FaultException<StockholmStadSystemErrorFault>(new StockholmStadSystemErrorFault(e.ErrorCode, e.Message));
            }
            catch (StockholmStadApplicationException e)
            {
                throw new FaultException<StockholmStadApplicationErrorFault>(new StockholmStadApplicationErrorFault(e.ErrorCode, e.Message));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public DateTime GetPreviousCeremonyDateForIndividualService(User user)
        {
            try
            {
                var ceremonyBusiness = new CeremonyBusiness(user);
                return ceremonyBusiness.GetPreviousCeremonyDateForIndividualService();
            }
            catch (StockholmStadSystemException e)
            {
                throw new FaultException<StockholmStadSystemErrorFault>(new StockholmStadSystemErrorFault(e.ErrorCode, e.Message));
            }
            catch (StockholmStadApplicationException e)
            {
                throw new FaultException<StockholmStadApplicationErrorFault>(new StockholmStadApplicationErrorFault(e.ErrorCode, e.Message));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public DateTime GetPreviousCeremonyDateForOrdinaryService(User user)
        {
            try
            {
                var ceremonyBusiness = new CeremonyBusiness(user);
                return ceremonyBusiness.GetPreviousCeremonyDateForOrdinaryService();
            }
            catch (StockholmStadSystemException e)
            {
                throw new FaultException<StockholmStadSystemErrorFault>(new StockholmStadSystemErrorFault(e.ErrorCode, e.Message));
            }
            catch (StockholmStadApplicationException e)
            {
                throw new FaultException<StockholmStadApplicationErrorFault>(new StockholmStadApplicationErrorFault(e.ErrorCode, e.Message));
            }
        }

        #endregion
    }
}
